<template>
  <div class="table">
<!--  <el-row class="topRow">
	  <el-dropdown>
	  <el-button type="primary">
		选择单位<i class="el-icon-arrow-down el-icon--right"></i>
	  </el-button>
	  <el-dropdown-menu slot="dropdown">
        <template v-for="item in compList">
            <el-dropdown-item @click.native="changeCompany(item.cpName)">{{ item.cpName }}</el-dropdown-item>
        </template>
	  </el-dropdown-menu>
	</el-dropdown>
  <el-tag>{{companyName}}</el-tag> -->
  </el-row>
    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="number"
        label="序号"
        width="80"
        align="center">
      </el-table-column>
      <el-table-column
        prop="name"
        label="录入信息名称"
        width="480"
        align="center">
      </el-table-column>
      <el-table-column
        prop="value"
        label="录入信息值"
        align="center">
        <template slot-scope="{row}">
          <el-form
            v-if="row.edit"
          >
            <el-form-item>
              <el-input v-model="row.value"  size="small"/>
            </el-form-item>
          </el-form>
          <span v-else>{{ row.value }}</span>
        </template>
      </el-table-column>
        <el-table-column align="center" label="操作" width="150" :resizable="false">
        <template slot-scope="{row}">
          <el-tooltip v-if="row.edit===1&&row.show===1" content="保存" placement="top">
            <el-button
              type="success"
              size="small"
              icon="el-icon-check"
              @click="checkEditSaveOk(row)"
            />
          </el-tooltip>
          <el-tooltip v-if="row.edit===0&&row.show===1" content="编辑" placement="top">
            <el-button
              type="primary"
              size="small"
              icon="el-icon-edit"
              @click="row.edit=1"
            />
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <el-row class="topRow">
        <el-button style="float:right;margin-right:50px" type="primary" @click="submit()">提交</el-button>
      </el-row>
    </div>
  </template>

  <script>
    import {getControl,updateControl,getAllCompany} from '@/api/budget'
    export default {
      data() {
        return {
          compList:[],
          companyName:"逆天",
          tableData: [
            {
              number: '1',
              name: '(1)公共预算拨款',
              value: '',
              edit:0,
               show:0
            },{
            number: '2',
            name: '1、财政下发控制数',
            value: '',
            edit:0,
             show:0
          }, {
            number: '3',
            name: '其中：因公出国（境）费用（公共预算拨款）',
            value: '',
            edit:0,
             show:1
          }, {
            number: '4',
            name: '其中：公务接待费（公共预算拨款）',
            value: '',
            edit:0,
             show:1
          }, {
            number: '5',
            name: '其中：公务用车运行维护费（公共预算拨款）',
            value: '',
            edit:0,
             show:1
          }, {
            number: '6',
            name: '2、部门下发控制数',
            value: '',
            edit:0,
             show:1
          }, {
            number: '7',
            name: '（2）专项资金项目',
            value: '',
            edit:0,
             show:0
          }, {
            number: '8',
            name: '专项资金项目（省级）',
            value: '',
            edit:0,
             show:0
          }, {
            number: '9',
            name: '专项资金项目（中央）',
            value: '',
            edit:0,
             show:0
          }, {
            number: '10',
            name: '（3）政府性基金拨款',
            value: '',
            edit:0,
             show:0
          }, {
            number: '11',
            name: '1、政府性基金拨款（省级）',
            value: '',
            edit:0,
             show:0
          }, {
            number: '12',
            name: '其中：因公出国（境）费用（政府性基金拨款（省级））',
            value: '',
            edit:0,
             show:0
          }, {
            number: '13',
            name: '其中：公务接待费（政府性基金拨款（省级））',
            value: '',
            edit:0,
             show:0
          }, {
            number: '14',
            name: '其中：公务用车运行维护费（政府性基金拨款（省级））',
            value: '',
            edit:0,
             show:0
          }, {
            number: '15',
            name: '2、政府性基金拨款（中央）',
            value: '',
            edit:0,
             show:0
          }, {
            number: '16',
            name: '其中：因公出国（境）费用（政府性基金拨款（中央））',
            value: '',
            edit:0,
             show:0
          }, {
            number: '17',
            name: '其中：公务接待费（政府性基金拨款（中央））',
            value: '',
            edit:0,
             show:0
          }, {
            number: '18',
            name: '其中：公务用车运行维护费（政府性基金拨款（中央））',
            value: '',
            edit:0,
             show:0
          }]
        }
      },
      created(){
        this.getControl(),
        this.getAllCompany()
      },
      methods:{
        checkEditSaveOk(row){
          row.edit = 0
        },
        getControl(){
          getControl().then(response =>{
            var data=response.data
            console.log(data)
            this.tableData[1].value=data.controlNum
            this.tableData[2].value=data.abroad
            this.tableData[3].value=data.office
            this.tableData[4].value=data.car
            this.tableData[5].value=data.controlNumDep
            this.tableData[7].value=data.specialFundProvince
            this.tableData[8].value=data.specialFundCenter
            this.tableData[9].value=data.fundProvince
            this.tableData[11].value=data.aboardProvince
            this.tableData[12].value=data.officeProvince
            this.tableData[13].value=data.carProvince
            this.tableData[14].value=data.fundCenter
            this.tableData[15].value=data.aboardCenter
            this.tableData[16].value=data.officeCenter
            this.tableData[17].value=data.carCenter
          })
        },
        getAllCompany(){
          getAllCompany(2).then(response=>{
            console.log(response)
			  var companyTotal=[];
			  var department=response.data;
			  //console.log(department)
			  for(var i=0;i<department.length;i++)
			  {
			    var company=department[i].companyInfoPOList;
			    //console.log(company)
			    for(var j=0;j<company.length;j++){
			      var companyEnd=company[j];
			      companyTotal.push(companyEnd)
			    }
			  }
			  this.compList=companyTotal
        console.log(this.compList)
			})
     },
        submit(){
          var data={};
          data.controlNum=this.tableData[1].value
          data.abroad=this.tableData[2].value
          data.office=this.tableData[3].value
          data.car=this.tableData[4].value
          data.controlNumDep=this.tableData[5].value
          updateControl(data).then(response=>{
            console.log(response)
            console.log("submit")
          })
        },
        changeCompany(name){
          console.log(name)
          this.companyName=name
        }
      }
    }
</script>
<style scoped>
.table{
  margin: 10px 20px 0;
}
</style>
